<?php

namespace frontend\models;

use Yii;
use yii\db\ActiveRecord;
use yii\db\Query;
use yii\behaviors\TimestampBehavior;
use yii\db\Exception;
/**
 * This is the model class for table "Team".
 *
 */
class Video extends ActiveRecord
{

    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%video}}';
    }


    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            TimestampBehavior::className(),
        ];
    }

    /**
     * 获取列表
     * @param $params
     * @author cpy(1442435897@qq.com)
     * @return array
     */
    public function getList($params){
        if(!empty($params['title'])){
            $condition= ['and',['like','title',trim($params['title'])],['deleted_at'=>null,'status'=>1]];
        }else{
            $condition = ['deleted_at'=>null,'status'=>1];
        }
        $list = (new Query())
            ->select('id,title,pic,intro,video,status,FROM_UNIXTIME(created_at) as create_time')
            ->from('video')
            ->orderBy('created_at desc')
            ->where($condition)
            ->all();
        return empty($list)?array():$list;

    }



}
